*** this do-file produces tables 1-4 and figures 1-5


cd "path_to_replication_folder"




// tab3: portfolio of the granular owner
***************************************************************************************************
* find large owner households of private firms and summarize their portfolio

u u if year==2016, clear
merge m:1 lnr year using lnr_hh_y
drop if _merge==2
drop _merge year

g lnr_h=lnr if hh==.
egen hhi = group(hh lnr_h lnr_for lnr_org), missing

preserve
keep if lnr!=.
keep lnr hhi
duplicates drop
save lnr_hhi_2016, replace
restore

collapse (sum) s, by(lnr_for lnr_org lnr_as hhi)

save u2016_hh, replace


* convert the portfolio composition to household level
u portfolio_size, clear
keep if lnr!=.
merge 1:1 lnr using lnr_hhi_2016 
drop if _m==1
collapse (sum) tid nlis ipt lis, by(hhi)
save oid_degree_tid_hh2016, replace


u u2016_hh, clear
keep if lnr_fo==. & lnr_org==.
g year=2016
merge m:1 lnr_as year using balance_sheets, keepusing(lis nlis iptra bof) 
drop if _m==2
drop _m
g lp = 1 if s>.05 & nlis==1  // large owners of private firms
egen Lp = total(lp), by(hhi)
keep if Lp>0
drop Lp lp

keep if s>.05 // blockholdings // total pf stats are merged below

egen traded = rowtotal(ipt lis)
drop ipt lis 

g snlis = s*nlis  // average of nlisted 
g stra = s*tra // average of listed

bysort hhi bof nlis: g N=_N if bof!=. & bof!=0

g Nnlis=N*nlis
g Ntra=N*trad // max number per sector

drop N
bysort hhi bof: g N=_N if bof!=. & bof!=0

// number of sectors per owner
replace bof=0 if bof==.
sort hhi nlis bo
bysort hhi nlis: g n=1 if bof!=bof[_n-1] & bof[_n-1]!=0  

g nnlis=n*nlis
g ntra=n*trad // max number per sector

drop n
bysort hhi nlis bof: g n=1 if bof!=bof[_n-1] & bof[_n-1]!=0  

collapse (sum) traded nlis nnlis ntra n (mean) snlis stra (max) Nnlis Ntra N, by(hhi)
rename nlis Nlnis
merge 1:1 hhi using oid_degree_tid_hh2016
drop if _m==2
drop _m

egen Traded = rowtotal(lis iptraded)
drop lis iptra

egen all_firms = rowtotal(Traded nlis)

foreach var of varlist _all {
	g md_`var' = `var'
	g p25_`var' = `var'
	g p75_`var' = `var'
	g p95_`var' = `var'
	g p90_`var' = `var'
	g m_`var' = `var'
	}

collapse  (mean) m_* (median) md_* (p25) p25_* (p75) p75_* (p90) p90_* (p95) p95_* (count) owners=tid

g dum=1
reshape long m_ md_ p25_ p75_ p90_ p95_, i(dum) j(type) string

keep if type=="Traded" | type=="traded" | type=="nlis"  | type=="Nlnis"  

g det= "\# private firms" if type=="nlis"
replace det= "\# private firms" if type =="Nlnis"
replace det= "max # per sector, total" if type =="N"
replace det= "max # per sector, non-listed" if type =="Nnlis"
replace det= "# sectors, big" if type =="n"
replace det= "\quad\# sectors" if type =="nnlis"
replace det= "\# public firms" if type =="Traded"
replace det= "\# public firms" if type =="traded"

g sort = 1 if type=="Traded"
replace sort=2 if type=="nlis"
replace sort=3 if type=="traded"
replace sort=4 if type=="Nlnis"

sort sort
g iq=p75-p25

replace m_ = round(m_,1) if m_>1
replace m_ = round(m_,.01) if m_<1


listtex det m_ md p90 p95 iq if sort<3 using tab3.tex, end(\\) replace
listtex det m_ md p90 p95 iq if sort>2 & sort<5 using tab3_2.tex, end(\\) replace



// sectors over # shareholdings

u u2016_hh, clear
keep if lnr_fo==. & lnr_org==.
g year=2016
merge m:1 lnr_as year using balance_sheets, keepusing(lis nlis iptra bof) 
drop if _m==2
drop _m

g lp = 1 if s>.05 & nlis==1  // large owners of private firms
egen Lp = total(lp), by(hhi)
keep if Lp>0
drop Lp lp
keep if s>.05 // blockholdings // total pf stats are merged below

// number of sectors per owner
replace bof=0 if bof==.

bysort hhi bof: g n=1 if bof!=bof[_n-1] & bof[_n-1]!=0  

collapse (sum) n  (count) tid=lnr_as (mean) s, by(hhi)
collapse (mean) n s (count) hhi (min) min=n , by(tid)


twoway (scatter n tid, msize(1) msymbol(square) mcolor(gs12))  (scatter min tid, msize(1.3) msymbol(plus)) (line n n, lcolor(black)) if tid>0 & tid<500 & hhi>4, graphregion(color(white)) scale(.8) legend(cols(3) label(1 "average # sectors")label(2 "minimum # sectors") label(3 "45-degree line")  ) xtitle("# blockholdings") ytitle("# sectors") xlabel(0(5)70) yticks(0(5)20) // version with group incl. 5+ individuals 

graph export fig2.pdf, replace


egen thhi=total(hhi)
g si=hhi/thhi

gsort -hhi
g sit=sum(si)

replace si = 1-sit+si if tid==7
replace si=. if tid>7

tostring tid, g(Tid)
replace Tid="7+" if tid==7 
graph bar si if tid<8, over(Tid) graphregion(color(white)) ylabel(0(.1).7)  ytitle("share of blockholders") b1title("# blockholdings") scale(.8)
graph export fig1.pdf, replace






// owners per firm
*********************************************************************************************************

u ownership_structure, clear
egen oid = rowtotal(iid fid eid)
collapse (mean) m_iid=iid m_fid=fid m_eid=eid m_oid=oid (median) md_oid=oid md_iid=iid md_fid=fid md_eid=eid (count) tid=lnr_as, by(nlis)
replace nlis=0 if nlis==.
save temp, replace



u direct_shares, clear
sort lnr_as hh lnr
bysort lnr_as hh: g n=_n
drop if n>1 & lnr!=. & hh!=.  // drop spouses 

collapse (count) oid=nom, by(lnr_as nlis)

collapse (mean) m_doid=oid (median) md_doid=oid, by(nlis)
replace nlis=0 if nlis==.
merge 1:1 nlis using temp
drop _m

reshape long @iid @fid @oid @doid @eid, i(nlis tid) j(stat) string


foreach var of varlist *id{
	replace `var' = round(`var',.1)
}

tostring *id, usedisplayformat replace force

replace stat = "mean" if stat=="m_"
replace stat = "median" if stat=="md_"

save tab1, replace




u u2016_hh, clear
keep if s>.05
g lnr=hhi if lnr_for==. & lnr_org==.

collapse (count) lnr lnr_for lnr_org, by(lnr_as)
g year=2016
merge m:1 lnr_as year using balance_sheets, keepusing(nlis)
drop if _m==2
drop _m


foreach var of varlist lnr lnr_f lnr_o {
	replace `var' = 0 if `var'==.
} // this is done to make sure firms without blockholders are counted

egen oid=rowtotal(lnr lnr_f lnr_or)
collapse (mean) m_iid=lnr m_fid=lnr_f m_eid=lnr_o m_oid=oid (median) md_oid=oid md_iid=lnr md_fid=lnr_f md_eid=lnr_o (count) tid=lnr_as, by(nlis)
replace nlis=0 if nlis==.
save temp1, replace



u direct_shares, clear
g lnr_h=lnr if hh==.
egen hhi = group(hh lnr_h lnr_for lnr_org), missing

collapse (sum) nom, by(lnr_as hhi)

keep if nom>.05

collapse (count) oid=nom, by(lnr_as)
g year=2016
merge m:1 lnr_as year using balance_sheets, keepusing(nlis lnr_as)
drop if _m==2
drop _m

replace oid=0 if oid==.
collapse (mean) m_doid=oid (median) md_doid=oid, by(nlis)
replace nlis=0 if nlis==.
merge 1:1 nlis using temp1
drop _m

reshape long @iid @fid @oid @doid @eid, i(nlis tid) j(stat) string

foreach var of varlist *id{
	replace `var' = round(`var',.1)
}


replace stat = "mean" if stat=="m_"
replace stat = "median" if stat=="md_"

tostring *id, usedisplayformat replace force

foreach var of varlist *id {
	rename `var' n_`var'
}

merge m:1 stat nlis using tab1
drop _m

listtex stat doid oid  iid eid fid n_doid n_oid n_iid n_eid n_fid if nlis==0 using tab2.tex, end(\\) replace  
listtex stat doid oid iid eid fid n_doid n_oid n_iid n_eid n_fid if nlis==1 using tab2_2.tex, end(\\) replace  

erase tab1.dta



// additional summary statistics reported in section 4.4

// number of firms with single blockholders


u u2016_hh, clear
keep if s>.05
g lnr=hhi if lnr_for==. & lnr_org==.
collapse (count) lnr lnr_for lnr_org, by(lnr_as)

gen o = lnr+lnr_for
collapse (count) lnr_as, by(o)
egen tln=total(lnr_as)
g s = lnr_as/tln
sum s if o==1

*** average share of the largest blockholder

u u2016_hh, clear
keep if s>.05
g lnr=hhi if lnr_for==. & lnr_org==.

drop if lnr_org!=.
collapse (max) s, by(lnr_as)

g year=2016
merge m:1 lnr_as year using balance_sheets, keepusing(nlis)
drop if _m==2
drop _m

sum s if nlis==1, d

sum s if nlis==., d
sum s, d



// share of state-owned firms

u u2016_hh, clear
keep if s>.05
g lnr=hhi if lnr_for==. & lnr_org==.
distinct lnr_as
global n1=r(ndistinct)

keep if lnr_orgnr!=.
distinct lnr_as
global n2=r(ndistinct)

di $n2/$n1


// Fig 3: number of firms with cross ownership


u ownership_structure, clear 
rename lnr_as lnr_j
merge 1:1 year lnr_j using balance_sheetsw, keepusing(agg_sec p9000)
drop if _m==2
drop _m
rename lnr_j lnr_i
merge 1:1 lnr_i year using kraw_ii
drop if _merge==2
drop _mer
g crossDum05=0
replace crossDum05=1 if s05>0 & s05!=.

replace agg_sec="services" if agg_sec=="pserv" | agg_sec=="serv"
replace agg_sec="mining" if agg_sec=="mini"
replace agg_sec="manufacturing" if agg_sec=="manu"
replace agg_sec="agriculture" if agg_sec=="agri"

collapse (sum) crossDum* (count) lnr, by(nlis agg_sec) 
egen N=total(lnr), by(agg_sec)

replace crossDum05=crossDum05/N
drop if agg_sec==""

replace nli=0 if nlis==.
drop lnr N
reshape wide crossDum*, i(agg_sec) j(nlis)

graph bar crossDum051 crossDum050, over(agg_se) stack ytitle("share of firms with common ownership") graphregion(color(white)) bar(1, color(gs6)) bar(2, color(gs6) fcolor(white)) legend(label(1 "private firms") label(2 "public firms")) ylabel(0(.1).3)
graph export fig3.pdf, replace



u ownership_structure, clear 
rename lnr_as lnr_j
merge 1:1 year lnr_j using balance_sheetsw, keepusing(bof p9000)
drop if _m==2
drop _m

rename lnr_j lnr_i
merge 1:1 lnr_i year using kraw_ii
drop if _merge==2
drop _mer
g crossDum05=0
replace crossDum05=1 if s05>0 & s05!=.

collapse (sum) crossDum* (count) lnr, by(nlis) 

replace crossDum05=crossDum05/lnr


foreach var of varlist c* {
	replace `var'=round(`var',.01)
}
g tp="Private" if nlis==1
replace tp="Public" if nlis==.

savesome tp crossDum05 using temp, replace




// Tab 1: sum stats on numbers and importance of listed and non-listed firms


u ownership_structure, clear 
rename lnr_as lnr_j
merge 1:1 year lnr_j using balance_sheetsw, keepusing(bof p9000)
drop if _m==2
drop _m
sort nlis bof
bysort nlis: g n=1 if bof!=bof[_n-1] & bof[_n-1]!=0  

sort nlis bof
bysort nlis bof: g N=_N // number of firms per sector

g s2 = n if N>1

distinct bof
global Nsec=r(ndistinct)

collapse (sum) s2 n (sum) p9000 (count) lnr, by(nlis)

egen R=total(p9000)
g r=p90/R  

egen N=total(lnr)
g nn=lnr/N
g ss2=s2/$Nsec

foreach var of varlist nn ss2 r {
	replace `var'=round(`var',.01)
}

g tp="Private" if nlis==1
replace tp="Public" if nlis==.

keep lnr nn ss2 r tp
merge 1:1 tp using temp
drop _m

sort lnr
listtex tp lnr_j nn r ss2 cross using tab1.tex, end(\\) replace  



** MHHI pictures

u balance_sheets, clear
keep if year==2016
drop if sales<0
collapse (sum) sales, by(bof shortname)
egen ts=total(sales)
g s_sales=sales/ts
keep bof s_sales sh
save sales_sec2016, replace


u balance_sheetsw, clear
keep if year==2016
g hhi=mr*mr
drop if mr==0
collapse (sum) hhi, by(bof)
save hhi2016, replace



u ksr_ii2016, clear
drop s1 
rename s05 sk
merge 1:1 sec_i sec_j using jsr_ii2016
drop _mer
drop s1 
rename s05 sj
merge 1:1 sec_i sec_j using msr_ii2016
drop _mer s1 
rename s05 sm
keep if sec_i==sec_j

rename sec_i bof
merge 1:1 bof using hhi2016
drop _merge

merge 1:1 bof using sales_sec2016
drop if _m==2
drop _merge


sum sj sk sm

replace sm=0 if sm==.
replace sk=0 if sk==.
replace sj=0 if sj==.

g mhhi=hhi+sm
gsort -mhhi
g mhhi2=hhi+sj

scatter mhhi mhhi2, msize(.7) graphregion(color(white)) ytitle("MHHI (ultimate)") xtitle("MHHI (direct)") 
graph export fig5.png, replace

g smmp=sm-sk

capture drop n
gsort -sk
g n=_n
graph hbar sk smmp hhi if n<41, over(shortname, sort(n)) stack scale(.4) graphregion(color(white)) legend(label(1 "MHHI Delta, private persons") label(2 "MHHI Delta, other ultimate owners") label(3 "HHI ") cols(3)) bar(1, color(dknavy)) bar(2, color(ltblue)) bar(3, color(gs10)) title("40 sectors with highest ownership concentration") note("Note: MHHI = HHI + MHHI Delta (private persons & foreign owners) + MHHI Delta (other ult. owners)")

graph display, xsize(20) ysize(23)
graph export fig4.png, replace

g cum_s=sum(s_sales)



************************************* corporates roles

** first identify firms which report corporate roles
u roles, clear
keep lnr_as
duplicates drop
g roles=1
save lnr_as_roles2016, replace



u dpowners_shares, clear
keep if year==2016

merge 1:m lnr lnr_as year using roles
drop if _m==2

collapse (count) lnr, by(lnr_as rtype)

merge m:1 lnr_as using lnr_as_roles2016
drop if _m==2
drop _m

replace rtype="NONE" if rtype==""
reshape wide lnr, i(lnr_as roles) j(rtype) string

foreach x in DAGL FF LEDE VARA NEST {
	capture g lnr`x'=.
}

g ceo = 1 if lnrDAGL!=. | lnrFF!=.
g board = 1 if lnrLEDE!=. | lnrVARA!=. | lnrNEST!=.
g indep = 1 if board==1 & ceo!=1

collapse (sum) ceo indep (count) lnr_as roles

foreach var of varlist ceo  indep {
	g s`var' = `var'/roles
}

* share of companies reporting roles
g sroles=roles/lnr_as
di sroles

foreach var of varlist s* {
	replace `var'=round(`var',.01)
}

keep sceo sindep lnr_as

reshape long s, i(lnr_as) j(role) string

g type="CEO" if role=="ceo"
replace ty="indep. board member" if role=="indep"
save temp, replace




u dpowners_shares, clear
keep if year==2016
merge 1:m lnr lnr_as year using roles
drop if _m==2
drop _m 

merge m:1 lnr_as using lnr_as_roles2016
keep if _m==3   


replace rtype="NONE" if rtype==""
rename lnr_as f

collapse (count) f, by(lnr rtype)

reshape wide f, i(lnr) j(rtype) string

foreach x in DAGL FF LEDE VARA NEST {
	capture g f`x'=.
}

g ceo = 1 if fDAGL!=. | fFF!=.
g board = 1 if fLEDE!=. | fVARA!=. | fNEST!=.
g indep = 1 if board==1 & ceo!=1

collapse (sum) ceo indep (count) lnr

foreach var of varlist ceo indep {
	g so`var' = `var'/lnr
	replace so`var'=round(so`var',.01)
}

keep soceo soindep lnr

reshape long so, i(lnr) j(role) string

merge 1:1 role using temp
keep if _m==3
drop _m

save temp2, replace




*** how many of these case overlap with common ownership

u roles, clear
g ceo=1 if rtype=="DAGL" | substr(rtype,1,2)=="FF"
g board = 1 if (rtype=="LEDE" | rtype=="VARA" | rtype=="NEST")

collapse (firstnm) ceo board, by(lnr lnr_as)
g indep=1 if board==1 & ceo!=1
drop board
drop if ceo!=1 & indep!=1
save ceo_long2016, replace


u u if year==2016, clear
keep if lnr!=. | lnr_for!=.
keep if s>.05
rename s s05
keep lnr lnr_for year lnr_as_orgnr s0*

merge m:1 lnr year using lnr_hh_y, keep(match master)
drop _mer
rename lnr_as_orgnr lnr_orgnr
replace lnr=. if hh!=.
egen hhi=group(lnr lnr_for hh), missing
collapse (sum) s*, by(hhi lnr_o lnr)
sort hhi
save temp, replace
u temp, clear
rename lnr_o lnr_i
rename s* s*_i
sort hhi
joinby hhi using temp
rename lnr_o lnr_j
rename s* s*_j
foreach x in 05  {
	g s`x'=s`x'_j*s`x'_i
	replace s`x'=. if s`x'==0
}
drop if lnr_i==lnr_j

g year=2016
rename (lnr_i lnr_j) (lnr_j lnr_jj)
merge m:1 lnr_j year using balance_sheetsw, keep(match) keepusing(bof)
drop _mer
destring bof, replace
rename bof sec_i

rename (lnr_j lnr_jj) (lnr_i lnr_j)
merge m:1 lnr_j year using balance_sheetsw,  keep(match) keepusing(bof)
drop _mer
destring bof, replace
rename bof sec_j

keep if sec_i==sec_j

rename lnr_i lnr_as_orgnr
merge m:1 lnr_as lnr using ceo_long2016
drop if _m==2
drop _m 

rename ceo ceo_i
rename indep indep_i

rename (lnr_as lnr_j) (lnr_i lnr_as_orgnr)
merge m:1 lnr_as lnr using ceo_long2016
drop if _m==2
drop _m 

rename ceo ceo_j
rename indep indep_j
rename lnr_as lnr_j

egen any=rowtotal(ceo* inde*)
keep if any>0

* the number of affected firms is

distinct lnr_i if ceo_i==1
global cofi_ceo = r(ndistinct)

distinct lnr_i if indep_i==1
global cofi_ind = r(ndistinct)

* the number of affected owners is
distinct lnr if ceo_i==1 
global co_ceo = r(ndistinct)

distinct lnr if indep_i==1 
global co_ind = r(ndistinct)

u temp2, clear

replace type="\ \textbf{and} blockholder in a competitor firm" 
replace s=$cofi_ceo/lnr_as if role=="ceo"
replace so=$co_ceo/lnr if role=="ceo"
replace s=$cofi_ind/lnr_as if role=="indep"
replace so=$co_ind/lnr if role=="indep"

replace s=round(s,.01)
replace so=round(so,.01)

append using temp2
gsort role -s


listtex type s  so  using tab4.tex, end(\\) replace  


* cleaning up

erase temp.dta
erase temp2.dta
erase ceo_long2016.dta
erase lnr_as_roles2016.dta
erase hhi2016.dta
erase sales_sec2016.dta
erase temp1.dta
erase oid_degree_tid_hh2016.dta
erase u2016_hh.dta
erase lnr_hhi_2016.dta

erase jsr_ii2016.dta
erase msr_ii2016.dta
erase ksr_ii2016.dta



